<?php
include("../header.inc");
require_once("../DataBase.inc");
require_once("../general_queries.inc");

$programs = query_programs()->execute();

?>
Add a new center manually:
<form name='manual' action='centers.php' method='post'>
Province: <select name='province_id'>
<?php foreach (DataBase::select("province",null,null,"province_name") as $p) echo "<option value='".$p["province_id"]."'>".$p["province_name"]."</option>";?>
</select><br/>
Interview center name: <input type='text' size=30 maxlength=50 name='interview_center_name'/><br/>
<button type='submit'>Create center</button>
</form>
<br/>
Or create it from an existing exam center:
<table border=1 cellpadding=2 style='border-collapse:collapse'>
<tr><th>Province</th><th>Centere name</th><th>Number of rooms</th><th>Eligible students</th><th>Action</th></tr>
<?php
$centers = DataBase::query("SELECT * FROM exam_center LEFT JOIN province on exam_center.province_id=province.province_id WHERE exam_center.selection_campaign_id=".$_SESSION["campaign_id"]." ORDER BY province_name,exam_center_name");
if ($centers<>false)
foreach ($centers as $center) {
	echo "<tr>";
	echo "<td>".$center["province_name"]."</td>";
	echo "<td>".$center["exam_center_name"]."</td>";
	$nb = DataBase::query("SELECT COUNT(*) FROM exam_center_rooms WHERE exam_center_id=".$center["exam_center_id"]);
	echo "<td>".$nb[0][0]."</td>";
			$q = "SELECT COUNT(DISTINCT applicant.applicant_id) FROM applicant_exam_room_beta";
			$q .= " LEFT JOIN applicant ON applicant.applicant_id=applicant_exam_room_beta.applicant_id";
			$where = "";
			foreach ($programs as $p) {
				$q .= " LEFT JOIN applicant_eligibility AS eligibility_".$p["program_id"]." ON (eligibility_".$p["program_id"].".applicant_id=applicant.applicant_id AND eligibility_".$p["program_id"].".program_id=".$p["program_id"].")";
				if ($where <> "") $where .= " OR ";
				$where .= "eligibility_".$p["program_id"].".eligible=1";
			}
			$q .= " WHERE applicant_exam_room_beta.exam_center_id=".$center["exam_center_id"]." AND applicant.excluded=0 AND applicant.selection_campaign_id=".$_SESSION["campaign_id"]." AND (".$where.")";
			$nb = DataBase::query($q);
	echo "<td>".$nb[0][0]."</td>";
	echo "<td>";
	echo "<a href='centers.php?import_exam_center=".$center["exam_center_id"]."&import_rooms=yes'>Make this exam center an interview center, and create the same rooms as for exam</a><br/>";
	echo "<a href='centers.php?import_exam_center=".$center["exam_center_id"]."&import_rooms=no'>Make this exam center an interview center, but do not reuse the same rooms</a><br/>";
	echo "</td>";
	echo "</tr>";
}
?>
</table>
<br/>
<a href='centers.php'>Go back to the list of interview centers</a>
<?php
include("../footer.inc");
?>